import schedule
import requests
import json
import yagmail
import datetime
import time
# pip install some-package -i https://pypi.tuna.tsinghua.edu.cn/simple

# "c:\program files\python\python38\python.exe" -m pip install --upgrade pip



def get_all_coins():
    sender = {"user": 'tianzhiguanlizixun@163.com', "password": 'VMUXBIXRSTMBJYDW', "host": 'smtp.163.com'}
    yag = yagmail.SMTP(sender['user'], sender['password'], host=sender['host'])
    try:
        url = "https://api.binance.com/api/v3/exchangeInfo"
        req = requests.get(url)
        all_data = json.loads(req.content)
        symbols = all_data['symbols']
        print(f"所有币种数量:{len(symbols)}")
        symbols = [(x['symbol'], x['baseAsset'], x['quoteAsset']) for x in symbols if x['status'] == 'TRADING']
        print(f"正常交易的币种数量:{len(symbols)}")
        for pair, baseAsset, quoteAsset in symbols:
            print(f"{baseAsset}/{quoteAsset}")
            assert pair == baseAsset + quoteAsset
        yag.send(to=['zhanghang0427@163.com'], subject="vpn_test_success", contents=f"{symbols}")
        print(f'{datetime.datetime.now()}邮件发送成功')
    except Exception as e:
        print(e)
        yag.send(to=['zhanghang0427@163.com'], subject="vpn_test_fail", contents=f"请检查vpn")
        print(f'{datetime.datetime.now()}邮件发送成功')


# 设置定时任务
schedule.every().day.at("08:30").do(get_all_coins)
schedule.every().day.at("12:30").do(get_all_coins)
schedule.every().day.at("17:00").do(get_all_coins)
schedule.every().day.at("22:00").do(get_all_coins)


get_all_coins()
while True:
    schedule.run_pending()
    time.sleep(1)  # 每秒检查一次
